<template>
  <div style="display: flex;flex-direction: column;width: 100%">
    <Header :activeName="activeName"></Header>
    <div style="display: flex;margin-top: 90px;height: 30px;line-height: 30px;justify-content: center;">
      <el-breadcrumb :separator-icon="ArrowRight" style="height: 30px;width: 80%;align-items: center;line-height: 30px">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>新闻资讯</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <main class="main">
      <div class="news-m-c">
        <div class="news-c" v-for="item in pageData">
          <div class="news-l-img-c">
            <img :src="item.pic" alt="" />
          </div>
          <div class="news-l-content">
            <p class="news-l-title">
              {{item.title}}
            </p>
            <p class="news-l-r-content overflow-wrap-ellipsis" v-html="item.content">
            </p>
            <p style="font-size: 18px;line-height: 18px;color: #6f6f6f;">
              2024-12-16
              <a class="news-view-o" :href="'/news/detail?nid='+item.id">查看原文</a>
            </p>
          </div>
        </div>
      </div>
      <div style="margin: 20px auto;display: flex;justify-content: center;">
<!--        <el-pagination
                       v-model:current-page="params.pageNum"
                       v-model:page-size="params.pageSize"
                       layout='total, prev, pager, next'
                       :total='params.total'
                       class='mt-4'
                       style='float: right'
                       @change='pages'/>-->
        <el-pagination
            size="small"
            background
            class='mt-4'
            v-model:current-page="params.pageNum"
            v-model:page-size="params.pageSize"
            layout='total, prev, pager, next'
            :total='params.total'
            @change='pages'
        />
      </div>
    </main>
    <BackTop></BackTop>
    <Footer></Footer>
  </div>

</template>

<script setup lang="ts">
import Header from '@/components/header/Header.vue'
import Footer from '@/components/header/Footer.vue'
import Breadcrumb from '@/components/Breadcumb.vue'
// import LatestGoods from '@/components/indexDecorate/decorateList/LatestGoods.vue'

import {onMounted, ref} from 'vue'
import {useRouter} from "vue-router";
import {ArrowRight} from "@element-plus/icons-vue";
import BackTop from "@/components/BackTop.vue";
import {newsPage} from "@/api/news.ts";

const router = useRouter()
const activeName = router.currentRoute.value.path

const params = ref({
  pageNum: 1,
  pageSize: 2,
  total: 0,
})

const pageData = ref([])

const pages = (currentPage: number, pageSize:number) => {
  getNewsPage()
}

const getNewsPage = () => {
  newsPage(params.value).then((resp) => {
    pageData.value = resp.data.records;
    params.value.total = resp.data.total;
    params.value.pageNum = resp.data.current;
    params.value.pageSize = resp.data.size;
  })
}

onMounted(()=>{
  getNewsPage()
})
</script>
<style scoped>
.main {
  width: 80%;
  position: relative;
  top: 20px;
  margin: auto;
  box-sizing: border-box;
  padding: 2px;
  border-top: 1px solid #4a4949;
  background-color: #fbf8f8;
}
.news-m-c {
  min-height: 800px;
}
.news-c {
  padding: 10px 10px 0;
  display: flex;
  border-bottom: 1px dashed #b6b2b2;
}
.overflow-wrap-ellipsis {
  overflow: hidden;white-space: nowrap;text-overflow: ellipsis;
}
.news-l-content{
  color: #000000;
  /*border: 1px solid red;*/
  width: 82%;
  flex-grow: 1;
  height: 150px;
  padding: 5px 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;white-space: nowrap;text-overflow: ellipsis;
}
.news-l-title{
  color: #000000;
  text-align: center;
  font-size: 20px;
  line-height: 20px;
  font-weight: bold
}
.news-l-c{
  padding: 10px 10px;
  color: #000000;
}
.news-l-img-c{
  width: 15%;
  height: 150px;
  text-align: center;
  border-radius: 5px;
  overflow: hidden;
}
.news-l-img-c img {
  object-fit: cover;
  width: 100%;
  height: 100%;
}
.news-l-r-content{
  margin-top: 10px;
  height: 230px;
}
.news-view-o {
  float: right;
  font-size: 18px;
  line-height: 18px;
  color: #979797;
  cursor: pointer;
}
a.news-view-o:hover {
  color: #444445;
  background-color: #cee1f4;
}
</style>
